package org.groupg.project.config;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule;
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import java.io.File;
import java.io.IOException;
import java.util.Map;

public class ConfigLoader {

    private static final ObjectMapper jsonMapper = new ObjectMapper();
    private static final XmlMapper xmlMapper = new XmlMapper();


    public static ProxyConfig loadConfig(String filePath) throws IOException {
        File configFile = new File(filePath);

        if (filePath.endsWith(".json")) {
            JsonProxyConfig jsonConfig = jsonMapper.readValue(configFile, JsonProxyConfig.class);
            return jsonConfig.toProxyConfig();
        } else if (filePath.endsWith(".xml")) {
            XmlProxyConfig xmlConfig = xmlMapper.readValue(configFile, XmlProxyConfig.class);
            return xmlConfig.toProxyConfig();
        }

        throw new IllegalArgumentException("Unsupported config file format: " + filePath);
    }
}